import React, {Component} from 'react';
import {NetInfo} from 'react-native';
import {isIOS} from "../../configs/platform";

export default class BaseComponent extends Component {

    componentDidMount() {
        if(isIOS()) {
            NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectionChange);
        }

        NetInfo.isConnected.fetch().done(
            (isConnected) => {
                if (!isConnected) {
                    // this.props.navigation.navigate('NetError');
                    global.netState = "无网络连接";
                }
                else{
                    global.netState = "正常";
                }
            }
        );
    }

    componentWillUnmount() {
        if(isIOS()) {
            NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectionChange);
        }
    }

    handleConnectionChange = (isConnected) => {
        if (!isConnected) {
            // this.props.navigation.navigate('NetError');
            global.netState = "无网络连接";
        }
        else{
            global.netState = "正常";
        }
    }
}
